<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="lib/bootstrap.min.css">
    <style>
    *{
        margin: 0;
        padding: 0;
    }
    body{
        background: url(img/1.jpg) no-repeat;
    }
    #box{
        width: 400px;
        height: 340px;
        border: 1px solid black;
        border-radius: 15px;
        position: fixed;
        left: 50%;
        top: 50%;
        transform: translate(-50%,-50%);
    }
    #box h3{
        position: fixed;
        left: 50%;
        transform: translateX(-50%);
        top: 40px;
    }
    #usermessage{
        /* border: 1px solid black; */
        /* width: 300px; */
        margin: 100px 0 0 50px;
    }
    #usermessage #username{
        margin-left: 5px;
    }
    #usermessage #password{
        margin-left: 7.5px;
    }
    #usermessage #name{
        margin-left: 7.5px;
    }
    #usermessage input{
        /* width: 200px; */
        border: none;
        outline: none;
    }
    #usermessage p{
        margin-bottom: 10px;
    }
    #button{
        position: fixed;
        left: 50%;
        transform: translateX(-50%);
        margin-top: 10px;
    }
    </style>
</head>
<body>
    <div id="box">
        <h3>欢迎注册</h3>
        <div id="usermessage">
        <p>
           <span>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名:</span>
            <input type="text" name="" id="name">
        </p>
        <p>
           <span>用&nbsp;&nbsp;户&nbsp;&nbsp;名:</span>
            <input type="text" name="" id="username">
        </p>
        <p>
            <span>密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码:</span>
            <input type="text" name="" id="password">
        </p>
        <p>
            <span>注册身份:</span>
            <input type="radio" name="identity" id="teacher" checked>教师
            <input type="radio"  id="student" name="identity">学生
        </p>
        </div>
        <div id="button">
            <!-- <button class="btn btn-primary" id="login">登录</button> -->
            <button class="btn btn-primary" id="register">注册</button>
        </div>
        
    </div>

    <script src="lib/common.js"></script>
    <script src="lib/jquery.min.js"></script>
    <script>
        $("#register").click(function(){
            // alert(1)
        if($("#username").val() && $("#password").val() && $("#name").val()){
            $.ajax({
                url:`${address}/adduser`,
                method:"post",
                data:{
                    username:$("#username").val(),
                    password:$("#password").val(),
                    name:$("#name").val(),
                    type:$("#student")[0].checked? 1 : 0
                    },
                    success(data){
                        if(data === "error"){
                            alert("注册失败！")
                        }
                        else{
                            alert("注册成功！")
                           
                                location.href = `${address}/login.html`
                        }
                    }
                })
            }
            else{
                alert("内容不能为空！")
            }
        })
    </script>
</body>
</html>